package priv.dajie.tzzq.spider.csgo.buff;

import org.apache.http.client.methods.HttpGet;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import priv.dajie.tzzq.Base;
import priv.dajie.tzzq.spider.csgo.SpiderInfoElement;
import priv.dajie.tzzq.spider.csgo.SpiderInfos;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName BuffCsgoInfo
 * @Description
 * @Author dajie
 * @Date 2019/11/10 8:55 上午
 * @Version V1.0
 **/
public class BuffCsgoInfo {

    private static Base httpclient = Base.getClientInstance();

    public static SpiderInfos getSpiderInfos(){
        String html = httpclient.open(new HttpGet("https://buff.163.com/market/?game=csgo"));
        Document document = Jsoup.parse(html);
        Elements elements = document.select("div.item.w-SelType.csgo_filter");
        List<SpiderInfoElement> spiderInfoElements = new ArrayList<>();
        for (Element element : elements){
            Element ul = element.selectFirst("ul.cols");
            if (ul == null){
                continue;
            }
            Elements items = ul.select("li");
            for (Element item : items){
                String key = "category";
                String value = item.attr("value");
                String type = item.text();
                SpiderInfoElement infoElement = new SpiderInfoElement(key, value, type);
                spiderInfoElements.add(infoElement);
            }
        }
        SpiderInfoElement infoElement = new SpiderInfoElement("category_group", "sticker", "印花");
        spiderInfoElements.add(infoElement);
        return new SpiderInfos(spiderInfoElements);
    }

    public static void main(String[] args) {
        SpiderInfos spiderInfos = getSpiderInfos();
        System.out.println(spiderInfos);
    }
}
